/**
 * 
 */
package org.hilo.boot.core.code;

import java.util.List;

/**
 * 
 * @author zollty
 * @since 2018年6月19日
 */
public class FieldMeta {

    private String name;
    private Class<?> type;
    private String comment;
    private String propertyType;
    private List<String> annotations;
    
    public FieldMeta() {
    }
    
    public FieldMeta(String name, Class<?> type, String comment) {
        super();
        this.type = type;
        this.name = name;
        this.comment = comment;
    }

    public String getPropertyType() {
        if (propertyType != null) {
            return propertyType;
        }
        return type.getSimpleName();
    }
    
    public void setType(Class<?> type) {
        this.type = type;
    }
    
    public Class<?> getType() {
        return type;
    }

    public String getPropertyName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * 按JavaBean规则来生成get和set方法
     */
    public String getCapitalName() {
        if (name.length() <= 1) {
            return name.toUpperCase();
        }
        String setGetName = name;
        // 第一个字母 小写、 第二个字母 大写，例如 dThing（对应getdThing/setdThing），直接返回
        String firstChar = setGetName.substring(0, 1);
        if (Character.isLowerCase(firstChar.toCharArray()[0])
            && Character.isUpperCase(setGetName.substring(1, 2).toCharArray()[0])) {
            return setGetName;
        }
        return firstChar.toUpperCase() + setGetName.substring(1);
    }

    /**
     * @return the annotations
     */
    public List<String> getAnnotations() {
        return annotations;
    }

    /**
     * @param annotations the annotations to set
     */
    public void setAnnotations(List<String> annotations) {
        this.annotations = annotations;
    }

    /**
     * @param propertyType the propertyType to set
     */
    public void setPropertyType(String propertyType) {
        this.propertyType = propertyType;
    }

}
